﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using University.Workshop.Model;

namespace University.Workshop.DataAccess
{
    public static class ClientRegistration
    {
        public static void AddClient(string fullName, string id, string telephone, string organization, string cell, string email, string birthDate, string fax, string country, string sex)
        {
            Client client = new Client
            {
                FullName = fullName,
                ClientId = id,
                Telephone = telephone,
                Organization = organization,
                Cell = cell,
                Email = email,
                Birthday = birthDate,
                Fax = fax,
                Country = country,
                Gender = sex
            }; 
            AddClient(client);
        }

        public static void AddClient(Client client)
        {
            if (client == null)
                throw new ArgumentException("Invalid Input Parameters");

            // La cadena de conexión
            const string conecctionString = "Data Source=.\\SQLEXPRESS; Initial Catalog=DataBaseHotel; Integrated Security=True";

            // Conectar y mostrar los datos
            using (SqlConnection conn = new SqlConnection(conecctionString))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.Parameters.Clear();
                cmd.CommandText = "INSERT INTO [Client]([FullName],[ClientId],[Telephone], [Organization], [Cellphone], [Email], [Birthday], [Fax], [Country], [Gender]) "
                    + "VALUES (@FullName, @ClientId, @Telephone, @Organization, @Cellphone, @Email, @Birthday, @Fax, @Country, @Gender)";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@FullName", client.FullName);
                cmd.Parameters.AddWithValue("@ClientId", client.ClientId);
                cmd.Parameters.AddWithValue("@Telephone", client.Telephone);


                cmd.Parameters.AddWithValue("@Organization", client.Organization);
                cmd.Parameters.AddWithValue("@Cellphone", client.Cell);
                cmd.Parameters.AddWithValue("@Email", client.Email);
                cmd.Parameters.AddWithValue("@Birthday", client.Birthday);
                cmd.Parameters.AddWithValue("@Fax", client.Fax);
                cmd.Parameters.AddWithValue("@Country", client.Country);
                cmd.Parameters.AddWithValue("@Gender", client.Gender);

                conn.Open();

                cmd.ExecuteNonQuery();
            }
        }
    }
}
